clear 
set more off

log using "${logs}/estimate_f0.log"

foreach paper in "ADGP1" "BDGP2" "CDGP3" "DDGP4" "EDGP5" "FDGP6" ///
		"GDGP7" "HDGP8" "IDGP9" "JDGP10" "KDGP11" {

	use "${dat}/DGP/`paper'_ScaledRunningVariable.dta", clear
	
	qui count
	local N = r(N)
	
	mata {
	
		X = st_data(.,("x"), 0)
		X_l = select(X,X:<0);	X_r = select(X,X:>=0)
		h_pilot_IK = 1.84*sqrt(variance(X))*length(X)^(-1/5)
		n_l_h1 = length(select(X_l,X_l:>=-h_pilot_IK))
		n_r_h1 = length(select(X_r,X_r:<=h_pilot_IK))
		f0_pilot=(n_r_h1+n_l_h1)/(2*`N'*h_pilot_IK)
	
		st_numscalar("f0_`k'", f0_pilot)
			}
			
	 di "Density estimator of DGP `paper': " f0_`k'		
				}

log close				
